/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.session;

import bean.entity.Interviews;
import bean.entity.Vacances;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author server
 */
@Stateless
@LocalBean
public class InterviewSessionBean {

    @PersistenceContext(unitName = "RecruitmentProcessSystem-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    public List<Interviews> findAllInterviewses(String empNo, Date date) {
        List<Interviews> list = null;
        try {
            Query query = em.createNamedQuery("Interviews.findByEmpNo");
            query.setParameter("empNo", empNo);
            query.setParameter("startdate", date);
            list = query.getResultList();
        } catch (NoResultException e) {
            return null;
        }
        return list;
    }

    public int countInterviews(String empNo, Date date) {
        int i = 0;
        try {
            i = ((Long) em.createNamedQuery("Interviews.countByEmpNo").setParameter("empNo", empNo).setParameter("startdate", date).getSingleResult()).intValue();
        } catch (NoResultException e) {
            return 0;
        }
        return i;
    }

    public void updateInterViews(List<Interviews> List) {
        for (Interviews i : List) {
            em.merge(i);
        }
    }

    public void updateOneInterViews(Interviews inter) {
        em.merge(inter);
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
}
